package com.ruoyi.dispatch.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.dispatch.domain.MonthWashReport;
import com.ruoyi.dispatch.enums.WashDayReportCol;
import com.ruoyi.dispatch.vo.WashDayReportVO;
import com.ruoyi.framework.utils.BeanCopyUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dispatch.domain.WashDayReport;
import com.ruoyi.dispatch.service.IWashDayReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 洗煤日报Controller
 * 
 * @author wuxiaofang
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/dispatch/washDayReport")
@Anonymous
public class WashDayReportController extends BaseController
{
    @Autowired
    private IWashDayReportService washDayReportService;

    /**
     * 查询洗煤日报列表
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:washDayReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(WashDayReport washDayReport,String[] columnArray)
    {
        startPage();
        List<WashDayReport> list = washDayReportService.selectWashDayReportList(washDayReport);
        //组装展示列名信息
        List<Map<String,String>> columns = null;
        if(columnArray!=null && columnArray.length!=0){
            columns = washDayReportService.handleColumnMap(columnArray);
        }
        TableDataInfo tableData =  getDataTable(list);
        tableData.setColumns(columns);

        return tableData;
    }

    /**
     * 导出洗煤日报列表
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:washDayReport:export')")
    @Log(title = "洗煤日报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WashDayReport washDayReport)
    {
        List<WashDayReport> list = washDayReportService.selectWashDayReportList(washDayReport);
        ExcelUtil<WashDayReport> util = new ExcelUtil<WashDayReport>(WashDayReport.class);
        util.exportExcel(response, list, "洗煤日报数据");
    }

    /**
     * 获取洗煤日报详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:washDayReport:query')")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return success(washDayReportService.selectWashDayReportByReportId(reportId));
    }

    /**
     * 新增洗煤日报
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:washDayReport:add')")
    @Log(title = "洗煤日报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WashDayReport washDayReport)
    {
        //插入数据
        int insertResult = washDayReportService.insertWashDayReport(washDayReport);

        //查询此次新增的记录
        WashDayReport report = washDayReportService.selectWashDayReportByReportId(washDayReport.getReportId());
        WashDayReportVO vo = BeanCopyUtils.copyProperties(report,WashDayReportVO.class);
        //组装默认展示的列信息
        vo.setDisplayCols(WashDayReportCol.getDefalutCols());

        return toAjax(insertResult,vo);
    }

    /**
     * 修改洗煤日报
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:washDayReport:edit')")
    @Log(title = "洗煤日报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WashDayReport washDayReport)
    {
        return toAjax(washDayReportService.updateWashDayReport(washDayReport));
    }

    /**
     * 删除洗煤日报
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:washDayReport:remove')")
    @Log(title = "洗煤日报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds)
    {
        return toAjax(washDayReportService.deleteWashDayReportByReportIds(reportIds));
    }
    @RequestMapping("countWashReport")
    public List<MonthWashReport> countWashReport(WashDayReport washDayReport){
        List<MonthWashReport> monthWashReportList = washDayReportService.countWashReport(washDayReport);
        return monthWashReportList;
    }
}
